<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBCommentModel extends AppModel
{
	
	var $tbl_pref_custom = 'kb_';
	var $tables = array('table'=>'comment', 'comment', 'entry');
	var $custom_tables = array('user');
	
	
	function getById($record_id) {
		$sql = "
		SELECT 
			c.*, 
			e.title,
			u.username,
			u.email AS r_email,
			UNIX_TIMESTAMP(c.date_posted) AS ts
		FROM 
			({$this->tbl->comment} c, 
			{$this->tbl->entry} e)
			LEFT JOIN {$this->tbl->user} u ON c.user_id = u.id
		WHERE 
			e.id = c.entry_id
			AND c.id = ?";
		$result = &$this->db->Execute($sql, $record_id) or die(db_error($sql));
		return $result->FetchRow();
	}
	

	function getRecordsSql() {
		
		$sql = "
		SELECT 
			c.*, 
			e.title,
			u.username,
			u.email AS r_email,
			UNIX_TIMESTAMP(c.date_posted) AS ts,
			CONCAT(SUBSTRING_INDEX(c.comment,' ',20), '...') AS comment
		FROM 
			({$this->tbl->comment} c, 
			{$this->tbl->entry} e)
			LEFT JOIN {$this->tbl->user} u ON c.user_id = u.id
		WHERE 
			e.id = c.entry_id  
			AND {$this->sql_params}
			{$this->sql_params_order}";
		
		//echo "<pre>"; print_r($sql); echo "</pre>";
		return $sql;
	}		
	
	
	
	
	
	// ACTIONS // ---------------------
	
	
	
	
	// DELETE RELATED // ---------------------
		
}
?>
